home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15736 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.3 KB  |  105 lines

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.os.linux.development.apps,comp.unix.programmer,comp.lang.c
  4. Subject: Re: Assembler Statement in C program
  5. Date: 21 Apr 1996 07:40:29 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4ldhctINNmdj@keats.ugrad.cs.ubc.ca>
  8. References: <317A2105.77EF485@bis.co.il>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <317A2105.77EF485@bis.co.il>, Meir Dukhan  <meir@bis.co.il> wrote:
  12. >Hi, 
  13. >
  14. >I'm trying to port some piece of C code to linux/unix.
  15. >This code contains statement in assembler.
  16. >
  17. >1. How can I compile it under linux with gcc or gas ?
  18.  
  19. You can't. It's not 32-bit code. GAS compiles 32-bit assembly language, and the
  20. instruction format is different from what the assemblers use under DOS.
  21. You should rewrite the code to conform.
  22.  
  23. >2. Will this be portable ?
  24.  
  25. Of course not. It's assembly language. A machine that doesn't share the same
  26. assembly language instruction set will not be able to make use of the code
  27. without some sort of translation or emulation, which defeats the purpose of
  28. coding in assembly in the first place.
  29.  
  30. >example:
  31. >
  32. >static void clear_screen(void)
  33. >{
  34. >    _asm
  35. >     {
  36. >         mov   ax,40h
  37. >         mov   es,ax
  38. >         mov   ax,0600h
  39. >         mov   bx,0700h
  40. >         mov   cx,0
  41. >         mov   dl, es:byte ptr[4ah]
  42. >         dec   dl
  43. >         mov   dh, es:byte ptr[84h]
  44. >         or    dh,dh
  45. >         jnz   k1
  46. >         mov   dh,24
  47. >k1:
  48. >         int   10h
  49. >         mov   dx,0
  50. >         mov   ax,0200h
  51. >         mov   bx,0
  52. >         int   10h
  53. >     }
  54. >}
  55.  
  56. You are making software interrupt calls to 16-bit bios here, which make no
  57. sense in any environment other than DOS. Also the area at segment 040H is
  58. unique to DOS. This has no hope of being portable to anything other than DOS,
  59. or systems that emulate DOS/BIOS functionality.
  60.  
  61. This is the most inane use of assembly language I have seen, considering that
  62. DOS compilers have the _int86() primitive for dealing with BIOS calls, not to
  63. mention <conio.h> screen functions for simple tasks like clearing the screen,
  64. positioning the cursor and the like.
  65.  
  66. It could all be done with existing, documented interfaces (however non standard
  67. they some of them may be).
  68.  
  69. Linux does not use direct screen writes to manage the screen, and it doesn't
  70. have a concept of an addressable screen area. You clear the screen by sending
  71. the appropriate control code to the terminal device. This method works on local
  72. consoles as well as remote terminals, or terminal emulator windows alike.
  73.  
  74. Learn how to use the curses library to do full-screen manipulation and
  75. character input on terminals. There are curses ports to DOS, so as an added
  76. benefit, your curses-based programs can be ported back to DOS.  
  77.  
  78. I'll give you a hint:
  79.  
  80. #include <stdio.h>
  81. #include <curses.h>
  82.  
  83. int main()
  84.  
  85. {
  86.     initscr();        /* initialize curses            */
  87.     noecho();        /* disable echo                */
  88.     cbreak();        /* disable input line processing    */
  89.  
  90.     /* put hello message at row 5, column 10 (home is 0,0)        */
  91.  
  92.     mvprintw(4, 9, "Hello, world!");
  93.  
  94.     refresh();    /* update terminal    */
  95.     getch();    /* wait for keystroke    */
  96.     erase();    /* erase screen        */
  97.     refresh();    /* update terminal    */
  98.     getch();    /* wait for another key    */
  99.     refresh();    /* update        */
  100.  
  101.     endwin();    /* stop curses        */
  102.  
  103.     return 0;
  104. }
  105.